<?php
session_start();
include_once 'objects/User.inc';
if (isset($_SESSION['user'])) {
    $user = unserialize($_SESSION['user']);
} else {
    $user = new User();
}
if (!$user->isLogged()) {
    header("Location: index.php");
    exit();
}

if (isset($_GET['id']))
    $obj = User::EId($_GET['id']);
else
    $obj = new User();
?><!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Agregar Usuario</title>
        <link rel="stylesheet" type="text/css" href="css/basic.css" />
        <script type="text/javascript" src="script/main.js"></script>
        <style type="text/css">
            body {
                background-color: #CCC;
            }
            body,td,th {
                color: #000;
                text-align: center;
                font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
            }
            table#form {
                text-align: center;
                color: #000;
            }
        </style>
    </head>
    <body>
        <input id="tmp" type="hidden">
        <img alt="logo2" src="img/boulevard.jpg" style="margin-top: 3em;"/>
        <?php
        if (isset($_COOKIE['msg'])) {
            echo "<p id=\"msg\" class=\"msg\">" . $_COOKIE['msg'] . "</p>";
            setcookie("msg", "", time() - 3600);
        } else {
            echo "<p id=\"msg\" class=\"error\">" . $obj->msg . "</p>";
        }
        ?>
        <table width="629" cellspacing="1" cellpadding="3" border="0" align='center'>
            <tr>
                <td width="621" bgcolor="#CA0000"><b><font color="#FFFFFF" size="3" face="verdana, arial, helvetica">AGREGAR USUARIO</font></b></td>
            <tr>
                <td height="238" bgcolor="#F5ECB9">
                    <table width="627" border="0" id='form'>
                        <tr>
                            <th width="109" scope="row"><label>Nombre de usuario:</label></th>
                            <td width="450"><input type="hidden" value='<?php echo $obj->encodeId(); ?>' id='formid' />
                                <span><input name="nombre" type="text" id="nombre" value="<?php echo $obj->nombre; ?>" /></span></td>
                        </tr>
                        <tr>
                            <th scope="row"><label>Clave:</label></th>
                            <td><span><input name="clave" type="password" id="preclave" /></span></td>
                        </tr>
                        <tr>
                            <th scope="row"><label>Validar Clave:</label></th>
                            <td><span><input name="clave" type="password" id="clave" /></span></td>
                        </tr>
                        <tr>
                            <th scope="row"><label>Permiso:</label></th>
                            <td><span><?php
                                    $provider = new Permiso();
                                    echo $provider->getSelect("permiso", $obj->permiso_id);
                                    ?></span></td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
        <br><br><br>
        <input type="button" name="guardar" id="guardar" value="Guardar" onclick="processForm('usuario');"/>
        <input type="button" name="button" id="button" value="Borrar" onclick="window.location = 'nuevousuario.php';"/>
        <input type="button" name="cancelar" id="volver" value="Volver" onclick="window.location = 'menu.php';" style="margin-bottom: 3em;"/>
        <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-width: 0; border-color: #111111; height: 53px" width="100%" id="AutoNumber3">
            <tr>
                <td width="100%" height="26" style="border-style: none; border-width: medium" bgcolor="#CA0000">
                    <p align="center"><b><font face="Arial" size="1" color="#000000">Proyectos Informaticos II /2013</font></b>
                </td>
            </tr>
        </table>
    </body>
</html>
